home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13946 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  43 lines

  1. Newsgroups: comp.lang.c,comp.unix.programmer
  2. Path: bcc.ac.uk!news
  3. From: Bill Zissimopoulos <B.Zissimopoulos@cs.ucl.ac.uk>
  4. Subject: Re: Q: '\n' character
  5. Message-ID: <3169994D.665ACF69@cs.ucl.ac.uk>
  6. Date: Mon, 8 Apr 1996 22:55:09 GMT
  7. Content-Transfer-Encoding: 7bit
  8. Content-Type: text/plain; charset=us-ascii
  9. References: <31616F63.481D@lava.weeg.uiowa.edu> <4jtddt$eu7@masala.cc.uh.edu> <DpBuF6.83C@ukpsshp1.serigate.philips.nl>
  10. Mime-Version: 1.0
  11. X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i586)
  12. Organization: University College London
  13.  
  14. Stephen Baynes wrote:
  15. > Spasmo (cosc19z5@Bayou.UH.EDU) wrote:
  16. > : Artur Wojdat (awojdat@lava.weeg.uiowa.edu) wrote:
  17. > : : Hello everybody,
  18. > : :     Is there a function or some sort of way that I could remove '\n'
  19. > : : charecter form the end of the string. I'm reading from two files, want to
  20. > : Dunno if there are any functions available, but what I always do
  21. > : is just overwrite the '\n' with a '\0', which does the job nicely.
  22. > : For example, let's say that the string that holds the data is called
  23. > : buf.  To get rid of the '\n' you'd merely do the following:
  24. > :       buf[strlen(buf) - 1] = '\0';
  25. > : And that takes care of that.
  26. > Thats the best way, but do check that the character you are about to overwrite
  27. > is a newline. There are two occasions when fgets stops without reading a
  28. > newline, first if it has filled your buffer (because you have a very long line
  29. > in the file), second if there is no newline at the end of the last line of the
  30. > file.
  31.  
  32. Which makes this the worst way for the exact reasons that you give.
  33.  
  34. -- 
  35. Bill Zissimopoulos <B.Zissimopoulos@cs.ucl.ac.uk>
  36. http://www-dept.cs.ucl.ac.uk/students/B.Zissimopoulos/
  37.  
  38.